package com.pig4cloud.pig.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.item.api.pojo.Category;
import com.pig4cloud.pig.item.mapper.CategoryMapper;
import com.pig4cloud.pig.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by caoxuel on 2020/10/14 11:44
 * @author caoxuel
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> getCategoryName() {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0);
        List<Category> categories = categoryMapper.selectList(queryWrapper);
        return categories;
    }

    @Override
    public List<Category> getSecondaryClass(String categoryName){
        QueryWrapper<Category> queryId = new QueryWrapper<>();
        queryId.eq("category_name", categoryName);
        Category categories1 = categoryMapper.selectOne(queryId);
        //Long parentId = categories1.getCategoryId();
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", categories1.getCategoryId());
        List<Category> categories = categoryMapper.selectList(queryWrapper);

        return categories;
    }


    @Override
    public Category getCategoryByName(String categoryName) {
        QueryWrapper<Category> query = new QueryWrapper<>();
        query.eq("category_name", categoryName);
        Category category = categoryMapper.selectOne(query);
        return category;
    }
}
